<%@ page language="java" pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%@ include file="../../common/common.jsp" %>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>${menu_name } - ${title }</title>
</head>
<link href="${ctx }/static/plugins/chosen_v1.6.2/chosen.css" rel="stylesheet"/>
<body
        <%@ include file="../../common/skin.jsp" %>
>
<%@ include file="../../common/head.jsp" %>
<%@ include file="../../common/menu.jsp" %>
<div class="J_content">
    <div class="mt20 plr20">
        <form action="${ctx }/course/list" id="queryForm" method="post">
            <div class="J_toolsBar clearfix">
                <div class="t_label">课程名称:</div>
                <div class="t_text ml10">
                    <input placeholder="请输入课程名称" type="text" name="name" id="name" value="${courseQueryDTO.name }"/>
                </div>
                <div class="t_label ml10">开课时间:</div>
                <div class="t_text ml10">
                    <input placeholder="开始时间" type="text" id="startTime" name="startTime"
                           onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" value="${startTimeStr }"  autocomplete="off">
                </div>
                <div class="t_label">~</div>
                <div class="t_text ml10">
                    <input placeholder="结束时间" type="text" id="endTime" name="endTime"
                           onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" value="${endTimeStr }"  autocomplete="off">
                </div>
                <div class="t_label ml10">是否是精英课程</div>
                <select name="isBest" class="t_opacitySelect ml10">
                    <option value="">请选择</option>
                    <option value="1" <c:if test="${'1' == courseQueryDTO.isBest }">selected="selected"</c:if>>是</option>
                    <option value="0" <c:if test="${'0' == courseQueryDTO.isBest }">selected="selected"</c:if>>否</option>
                </select>
                <div class="t_button mgl30">
                    <a class="abtn red" href="javascript:myQuery();">
                        <i class="icon"></i>查询
                    </a>
                </div>
                <div class="t_button ml10">
                    <a class="abtn blue" href="javascript:myEdit();">
                        <i class="icon"></i>新增
                    </a>
                </div>
                <div class="t_label ml10">
                    记录数：<label style="color: red;" id="total">${page.totalCount }</label>
                </div>
            </div>

            <div class="J_table mt20">
                <div class="t_table">
                    <table>
                        <thead>
                        <tr>
                            <td>
                                <span>序号</span>
                            </td>
                            <td>
                                <span>课程封面</span>
                            </td>
                            <td>
                                <span>课程名称</span>
                            </td>
                            <td>
                                <span>课程分类</span>
                            </td>
                            <td>
                                <span>开课时间</span>
                            </td>
                            <td>
                                <span>精英课程</span>
                            </td>
                            <td>
                                <span>操作</span>
                            </td>
                        </tr>
                        </thead>
                        <tbody>
                        <c:choose>
                            <c:when test="${page.list != null && page.totalCount > 0 }">
                                <c:forEach items="${page.list }" var="u" varStatus="status">
                                    <tr>
                                        <td>
                                            <div class="t_text tc">
                                                    ${status.index+1 }
                                            </div>
                                        </td>
                                        <td>
                                            <div class="t_text tc">
                                                <img src="${ctx }${u.coverImg}" alt=""
                                                     style="width: 60px; height: 50px">
                                            </div>
                                        </td>
                                        <td>
                                            <div class="t_text tc">
                                                    ${u.name }
                                            </div>
                                        </td>
                                        <td>
                                            <div class="t_text tc">
                                                    ${u.courseCateName }
                                            </div>
                                        </td>
                                        <td>
                                            <div class="t_text tc">
                                                    ${u.startTime }
                                            </div>
                                        </td>
                                        <td>
                                            <div class="t_text tc">
                                                <c:choose>
                                                    <c:when test="${u.isBest eq '0' }">
                                                        不是
                                                    </c:when>
                                                    <c:otherwise>
                                                        <font color="red">是</font>
                                                    </c:otherwise>
                                                </c:choose>
                                            </div>
                                        </td>
                                        <td>
                                            <div class="t_link">
                                                <a href="javascript:myEdit('${u.id }');"><i class="icon"></i>编辑</a>
                                                <a href="javascript:updStatus('${u.id }', '1');"><i class="icon"></i>删除</a>
                                            </div>
                                        </td>
                                    </tr>

                                </c:forEach>
                            </c:when>
                            <c:otherwise>
                                <tr>
                                    <td colspan="8">
                                        <div class="J_null mt40">
                                            <img src="${ctx }/static/images/null.png">
                                            <p>暂无相关数据</p>
                                        </div>
                                    </td>
                                </tr>
                            </c:otherwise>
                        </c:choose>
                        </tbody>
                    </table>
                </div>
                <%@ include file="../../common/pager.jsp" %>
            </div>
        </form>
    </div>
</div>
<script src="${ctx }/static/plugins/chosen_v1.6.2/chosen.jquery.js"></script>
<script type="text/javascript">
    function myEdit(id) {
        window.location.href = '${ctx}/course/edit?id=' + id;
    }

    function mySubmit() {
        $('#editForm').submit();
    }

    function myQuery() {
        $('#queryForm').submit();
    }

    function myExport() {
        var userName = $("#userName").val();
        window.location.href = "${ctx}/user/export?userName=" + userName;
    }

    function updStatus(id, status) {
        var content = '';
        if (status == '1') {
            content = '确认要恢复数据吗？';
        } else {
            content = '确认要删除数据吗？';
        }

        layer.confirm(content, function (index) {
            layer.close(index);
            var loadIdx = layer.load();
            $.ajax({
                url: '${ctx}/course/ajax/del',
                type: 'post',
                data: {
                    'id': id,
                },
                traditional: true,
                success: function (result) {
                    layer.close(loadIdx);
                    if (result.success) {
                        layer.alert('操作成功', function () {
                            window.location.reload();
                        });
                    } else {
                        layer.alert('操作失败');
                    }
                }
            });
        });
    }
</script>
</body>
</html>